import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';


@Injectable({
  providedIn: 'root'
})
export class RequestService {

  constructor() {
  }

  getDataByPromise() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve('Promise异步数据');
      }, 2000);
    });
  }

  getDataByRxjs() {
    return new Observable((ob) => {
      setTimeout(() => {
        ob.next('Rxjs异步数据');
      }, 3000);
    });
  }

  getIntervalDataByRxjs() {
    let count = 0;
    return new Observable((ob) => {
      setInterval(() => {
        count++;
        ob.next(count);
      }, 1000);
    });
  }

}
